package router

import (
	"github.com/starmotioncf/soutchatinternal/handler"
	"github.com/starmotioncf/soutchatinternal/middleware"

	"github.com/gin-gonic/gin"
)

//
//
// WithoutLoginRouter 非强制登陆接口，第三方回调的接口不要放到这里 ！！！！
//
//

type WithoutLoginRouter struct {
	authMiddleware        *middleware.AuthMiddleware
	maskChinaMiddleware   *middleware.MaskChinaMiddleware
	restrictionMiddleware *middleware.RestrictionMiddleware
	commonHandler         *handler.CommonHandler
	accountHandler        *handler.AccountHandler
	countryHandler        *handler.CountryHandler
	smsHandler            *handler.SmsHandler
}

func NewWithoutLoginRouter(authMiddleware *middleware.AuthMiddleware, maskChinaMiddleware *middleware.MaskChinaMiddleware,
	restrictionMiddleware *middleware.RestrictionMiddleware,
	commonHandler *handler.CommonHandler, accountHandler *handler.AccountHandler,
	countryHandler *handler.CountryHandler, smsHandler *handler.SmsHandler) *WithoutLoginRouter {
	return &WithoutLoginRouter{
		authMiddleware:        authMiddleware,
		maskChinaMiddleware:   maskChinaMiddleware,
		restrictionMiddleware: restrictionMiddleware,
		commonHandler:         commonHandler,
		countryHandler:        countryHandler,
		accountHandler:        accountHandler,
		smsHandler:            smsHandler,
	}
}

func (r *WithoutLoginRouter) Register(gr gin.IRouter) {
	// 注册中间件
	gr = gr.Group("", r.authMiddleware.CheckLoginHandler(),
		r.maskChinaMiddleware.Handle, r.restrictionMiddleware.Handle)
	gr.GET("/", r.commonHandler.Version)
	r.common(gr)
	r.country(gr)
	r.account(gr)
}

// common 其他的公共接口
func (r *WithoutLoginRouter) common(gr gin.IRouter) {
}

func (r *WithoutLoginRouter) country(gr gin.IRouter) {
	gr.GET("/country", r.countryHandler.GetList) //获取国家列表，分区
}

// account 账户登陆相关
func (r *WithoutLoginRouter) account(gr gin.IRouter) {
	gr.POST("/third_login", r.accountHandler.LoginByThird)           //第三方登陆
	gr.POST("/login", r.accountHandler.LoginByPhoneAndPwd)           //密码登陆
	gr.POST("/sms_login", r.accountHandler.LoginByPhoneAndCaptcha)   //验证码登陆
	gr.PUT("/mobile_phone/check", r.accountHandler.CheckMobilePhone) //检查手机注册信息
	gr.PUT("/reset_password", r.accountHandler.ResetPwd)             //重置密码
	gr.POST("/sms/captcha", r.smsHandler.SendCaptcha)                //发送短信
}
